The Building Blocks of a Central Application
Table of Contents
The Pod
When building the application, I wanted to make sure that only one pod is open when I make a call to viewPod() during the onActivate()function.
But how do you determine if the pod is still open from the last time you viewed
the application? If you don't detect pods that are already open, you will end
up with multiple, identical pods—one for each time you restart the application
without closing Central.
You can solve the problem with the almost "magical" method, getViewedPods().
Note that you put this code in the application FLA, not the pod:
// get array of pods
pods = shell.getPods();
// there is only one pod for this app, so it must be the first in the list
myPod = pods[0];
// get viewed pods
viewedPods = shell.getViewedPods();
if (viewedPods.length == 0) {
// if the array of viewed pods has a length of 0, no pod is currently
// open for this app, so it's safe to open one; otherwise don't
shell.viewPod(myPod.id);
}
Every time the application activates, I check if there are any viewed pods. If (and only if) there aren't any, I open the pod.
Figure 2. Sample pod
Below is the basic structure of the init.as file the pod uses. Again, this is just a skeleton. The pod in the sample application also includes a function to receive notices, which I will explain later.
function onActivate(dock, podid, viewerId, position, baseTabIndex, data)
{
// create console reference
this.gConsole = dock;
}
function onDeactivate()
{
/*
put other deactivation code here
Example: code to store data locally
*/
}
function onNetworkChange( connected )
{
/*
put code here that will execute when the user
is disconnected from internet
*/
}
// any other functions you may need
function anotherPodFunction() {
…
}
// init the pod
Central.initPod( this, this );